package com.sinosoft.perfect.system.chooseComponent.action;

import java.io.IOException;
import java.io.PrintWriter;
import java.sql.SQLException;
import java.util.List;

import com.sinosoft.perfect.common.system.BaseAction;
import com.sinosoft.perfect.system._.po.TUnit;
import com.sinosoft.perfect.system._unit.service.IUnitService;
import com.sinosoft.perfect.system.chooseComponent.dataFormat.IChooseUnitGridDataFormat;

@SuppressWarnings("serial")
public class ChooseUnitAction extends BaseAction {

	private IChooseUnitGridDataFormat ichooseUnitGridDataFormat;
	private IUnitService iUnitService;
	
	public IChooseUnitGridDataFormat getIchooseUnitGridDataFormat() {
		return ichooseUnitGridDataFormat;
	}
	public void setIchooseUnitGridDataFormat(
			IChooseUnitGridDataFormat ichooseUnitGridDataFormat) {
		this.ichooseUnitGridDataFormat = ichooseUnitGridDataFormat;
	}
	public IUnitService getiUnitService() {
		return iUnitService;
	}
	public void setiUnitService(IUnitService iUnitService) {
		this.iUnitService = iUnitService;
	}

	public String queryUnitInfoByUnitIds() throws IOException {
		response.setContentType("text/xml;charset=UTF-8");
		response.setHeader("Cache-Control", "no-cache");
		String resultXml = null;
		try {
			List<TUnit> tus = iUnitService.selectTUnitByUnitIds(request.getParameter("unitIds"));
			resultXml = ichooseUnitGridDataFormat.dataFormatUnitGrid(tus);

		} catch (SQLException e) {
			e.printStackTrace();
			session.put("exceptionInfoClass", e);
			return "exceptionOperateAction";
		}
		PrintWriter out = response.getWriter();
		out.print(resultXml);
		out.flush();
		out.close();
		return null;
	}
	
	
}
